package doc2db.interfaces.mainWindow;

import doc2db.Keey;
import doc2db.Launcher;
import doc2db.UserProp;
import doc2db.interfaces.action.ExitAction;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JScrollPane;

/**
 *
 * @author yuriy
 */
public class MyFrame extends JFrame{
    public MyPanel pane ;//= new MyPanel(this);
    public MyMenu menu ;//= new MyMenu(this);
    public MyToolBar toolBar ;//= new MyToolBar(this);
    public VMemory vm ;

    public MyFrame(JScrollPane t){
        this.frameProp();
        this.initComponent(t);
    }

    private void frameProp(){
        setTitle("doc2db");
        try {
            setIconImage(Launcher.getImage("main.jpg"));
        } catch (Exception ex) {
            if(Keey.debug){
                System.err.println("Can init window image :" + ex);
            }
        }

        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent arg0) {
                new ExitAction(MyFrame.this).actionPerformed(null);
            }
        });
        setResizable(true);
        setSize(UserProp.size);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        setMinimumSize(new Dimension(300, 464));
        setLocation(UserProp.location.width, UserProp.location.height);
    }

    private void initComponent(JScrollPane t){
        pane = new MyPanel(this, t);
        toolBar = new MyToolBar(this);
        menu = new MyMenu(this);
        Container c = this.getContentPane();

        c.setLayout(new BorderLayout());
        c.add(pane, BorderLayout.CENTER);
        c.add(toolBar, BorderLayout.NORTH);
        this.initMenuBar();
    }

    public void initMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);
        menuBar.add(menu.getMenu());
        menuBar.add(menu.getCorrect());
        menuBar.add(menu.getBd());
        menuBar.add(menu.getHelp());
    }    
    
}
